package com.chookss.view;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.chookss.R;
import com.chookss.home.rank.RankEntity;
import com.chookss.tools.Utils;
import com.chookss.view.listener.ShareDialogListener;

import butterknife.BindView;

public class RankDialog extends BaseDialog {

    @BindView(R.id.tvSure)
    TextView tvSure;
    @BindView(R.id.tvAttribution)
    TextView tvAttribution;
    @BindView(R.id.tvType)
    TextView tvType;
    @BindView(R.id.tvContent)
    TextView tvContent;
    @BindView(R.id.tvSource)
    TextView tvSource;
    @BindView(R.id.tvTime)
    TextView tvTime;
    @BindView(R.id.llType0)
    LinearLayout llType0;
    @BindView(R.id.tvDate)
    TextView tvDate;
    @BindView(R.id.tvAccess)
    TextView tvAccess;
    @BindView(R.id.tvUsers)
    TextView tvUsers;
    @BindView(R.id.tvName)
    TextView tvName;
    @BindView(R.id.llType1)
    LinearLayout llType1;
    @BindView(R.id.llName)
    LinearLayout llName;
    private int type;
    private Context context;
    private RankEntity rankEntity;
    private ShareDialogListener listener = null;

    public RankDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_rank;
    }

    @Override
    protected void init(View view) {
        initCenter(0.3f);
        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    public RankDialog(@NonNull Context context, int dayType, RankEntity rankEntity) {
        super(context);
        this.context = context;
        this.rankEntity = rankEntity;
        if(Utils.isNull(rankEntity.getNickname())){
            llName.setVisibility(View.GONE);
        }else{
            tvName.setText(rankEntity.getNickname());
            llName.setVisibility(View.VISIBLE);
        }

        if (dayType == 5) {
            llType0.setVisibility(View.VISIBLE);
            llType1.setVisibility(View.GONE);
            tvAttribution.setText(rankEntity.getRegion() + rankEntity.getCity());
            tvContent.setText(rankEntity.getResourceName());
            tvSource.setText(rankEntity.getUserSource());
            if ("0".equals(rankEntity.getUserType())) {
                tvType.setText("游客");
            } else if ("1".equals(rankEntity.getUserType())) {
                tvType.setText("粉丝");
            } else {
                tvType.setText("会员");
            }
            tvTime.setText(Utils.getAccurateDate(rankEntity.getCreateTime()));
        }else{
            llType0.setVisibility(View.GONE);
            llType1.setVisibility(View.VISIBLE);
            tvAccess.setText(rankEntity.getVisitNum());
            tvUsers.setText(rankEntity.getEmpNum());
            if (Utils.isNull(rankEntity.getWeekNo())) {
                tvDate.setText(rankEntity.getCreateTime());
            } else {
                tvDate.setText(rankEntity.getYearNo() + "年第" + rankEntity.getWeekNo() + "周");
            }
        }


    }
}
